package stz.flash.option.flashlight;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import stz.flash.option.OptionLabel;
import stz.flash.string.OptionInformation;
import stz.flash.string.OptionString;
import blackberry.util.field.DjCheckboxField;
import blackberry.util.field.DjLabelField;


public class FlashlightStartupStateCheckbox extends DjCheckboxField implements FieldChangeListener{

	public FlashlightStartupStateCheckbox() {
		super(DjLabelField.createSimpleLabel(OptionString.FLASHLIGHT_STARTUP_STATE_CHECKBOX_LABEL), 
				OptionLabel.createInfoLabel(OptionInformation.FLASHLIGHT_STARTUP_STATE_CHECKBOX_INFORMATION),
				FlashlightOption.getIns().isStartupFlashState());
		setChangeListener(this);
	}
	
	public void fieldChanged(Field field, int context) {
		if (PROGRAMMATIC == context) {
			return;
		}
		if (getChecked()) 
			setStartupFlashState(true);
		else 
			setStartupFlashState(false);
	}

	private void setStartupFlashState(boolean flashState) {
		FlashlightOption.getIns().setStartupAndCurrentFlashState(flashState);
	}
}